<template>
  <BasicModal v-bind="$attrs" @register="descriptionRegister" :title="'订单详情'" @ok="handleSubmit" style="background-color: red">
    <BasicForm @register="registerForm"  />
  </BasicModal>

<!--  <BasicModal v-bind="$attrs" @register="registerModal" :title="isUpdate ? t('action.edit') : t('action.create')" @ok="handleSubmit">
    <BasicForm @register="registerForm" />
  </BasicModal>-->


</template>
<script lang="ts" setup>
import { ref, unref } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'
import { BasicForm, useForm } from '@/components/Form'
import { BasicModal, useModalInner } from '@/components/Modal'
import { createFormSchema, updateFormSchema } from './order.data'
import { createOrder, getOrder, updateOrder } from '@/api/seatransportation/order'

defineOptions({ name: 'OrderModal' })

const { t } = useI18n()
const { createMessage } = useMessage()
const emit = defineEmits(['success', 'register'])
const isUpdate = ref(true)

const [registerForm, { setFieldsValue, resetFields, resetSchema, validate }] = useForm({
  labelWidth: 60,
  baseColProps: { span: 9 },
  schemas: createFormSchema,
  showActionButtonGroup: false,
  actionColOptions: { span: 23 }
})

const [descriptionRegister, { setModalProps, closeModal }] = useModalInner(async (data) => {
  resetFields()
  setModalProps({ confirmLoading: false })
  isUpdate.value = !!data?.isUpdate
  console.log("成功弹出警告框！",data)
//unref(isUpdate)
  if (true) {
    alert(data.record.orderid)

    resetSchema(createFormSchema)
    const res = await getOrder(data.record.orderid)
    setFieldsValue({ ...res })
  }
})

async function handleSubmit() {
  closeModal()

  try {
   /* const values = await validate()
    setModalProps({ confirmLoading: true })
    if (unref(isUpdate)) {
      await updateOrder(values)
    } else {
      await createOrder(values)
    }
    emit('success')
    createMessage.success(t('common.saveSuccessText'))*/
  } finally {
    setModalProps({ confirmLoading: false })
  }
}
</script>
